package com.yin.jia.liang.service;

import com.yin.jia.liang.dao.ContactMapper;
import com.yin.jia.liang.dao.GoodsOrderMapper;
import com.yin.jia.liang.entity.Contact;
import com.yin.jia.liang.entity.ContactExample;
import com.yin.jia.liang.entity.GoodsOrder;
import com.yin.jia.liang.entity.GoodsOrderExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContactService {

    @Autowired
    ContactMapper contactMapper;

    public Contact findById(Integer id) {
        return contactMapper.selectByPrimaryKey(id);
    }

    public List<Contact> findByUserId(int userId) {
        ContactExample ue = new ContactExample();
        ContactExample.Criteria criteria = ue.createCriteria();
        criteria.andUserIdEqualTo(userId);
        ue.setOrderByClause("id desc");
        List<Contact> g = contactMapper.selectByExampleWithBLOBs(ue);

        return g;
    }

    public List<Contact> find() {
        ContactExample ue = new ContactExample();
        ue.setOrderByClause("id desc");
        List<Contact> g = contactMapper.selectByExampleWithBLOBs(ue);

        return g;
    }

    public Integer save(Contact order) {
        int i = contactMapper.insert(order);
        return i;
    }

    public int update(Contact order) {
        int i = contactMapper.updateByPrimaryKeySelective(order);
        return i;
    }

    public Integer delete(Integer id) {
        return contactMapper.deleteByPrimaryKey(id);
    }
}
